package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.ReEvaluate;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReBonus;
import com.ruoyi.system.service.IReBonusService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销积分设定Controller
 * 
 * @author ruoyi
 * @date 2023-12-22
 */
@Controller
@RequestMapping("/system/bonus")
public class ReBonusController extends BaseController
{
    private String prefix = "system/bonus";

    @Autowired
    private IReBonusService reBonusService;

    @Autowired
    private ISysUserService userService;

    @RequiresPermissions("system:bonus:view")
    @GetMapping()
    public String bonus()
    {
        return prefix + "/bonus";
    }

    /**
     * 查询分销积分设定列表
     */
    @RequiresPermissions("system:bonus:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReBonus reBonus)
    {
        startPage();
        List<ReBonus> list = reBonusService.selectReBonusList(reBonus);
        return getDataTable(list);
    }

    /**
     * 导出分销积分设定列表
     */
    @RequiresPermissions("system:bonus:export")
    @Log(title = "分销积分设定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReBonus reBonus)
    {
        List<ReBonus> list = reBonusService.selectReBonusList(reBonus);
        ExcelUtil<ReBonus> util = new ExcelUtil<ReBonus>(ReBonus.class);
        return util.exportExcel(list, "分销积分设定数据");
    }

    /**
     * 新增分销积分设定
     */
//    @GetMapping("/add/{id}")
//    public String add(@PathVariable("id") Long id, ModelMap mmap)
//    {
//        SysUser puser = userService.selectUserById(id);
//        mmap.put("puser", puser);
//        return prefix + "/add";
//    }

    @GetMapping("/add")
    public String add()
    {

        return prefix + "/add";
    }

    /**
     * 新增保存分销积分设定
     */
    @RequiresPermissions("system:bonus:add")
    @Log(title = "分销积分设定", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReBonus reBonus)
    {
        reBonus.setCreateBy(getLoginName());
        return toAjax(reBonusService.insertReBonus(reBonus));
    }

    /**
     * 修改分销积分设定
     */
    @RequiresPermissions("system:bonus:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ReBonus reBonus = reBonusService.selectReBonusById(id);
        mmap.put("reBonus", reBonus);
        return prefix + "/edit";
    }

    /**
     * 修改保存分销积分设定
     */
    @RequiresPermissions("system:bonus:edit")
    @Log(title = "分销积分设定", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReBonus reBonus)
    {

        reBonus.setUpdateBy(getLoginName());
        return toAjax(reBonusService.updateReBonus(reBonus));
    }

    /**
     * 删除分销积分设定
     */
    @RequiresPermissions("system:bonus:remove")
    @Log(title = "分销积分设定", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reBonusService.deleteReBonusByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "分销积分--是否启用", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:evaluate:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(ReBonus reBonus)
    {

        return toAjax(reBonusService.updateReBonus(reBonus));
    }
}
